package com.algorithm.find;

import java.util.Arrays;

/**
 * @author chenqb
 * @version 1.0
 * @description: 二分查找算法
 * @date 2021/10/15 10:21
 */
public class Search {
    public static void main(String[] args) {
        int[] nums = {-1, 0, 6, 3, 9, 12};
        System.out.println(Search.findSearch(nums, 9));
    }

    public static int findSearch(int[] nums, int target) {
        int result = 0;
        //如果存在 返回目标元素在数组中的下标，else返回-1
        int zh = nums.length / 2;
        for (int i = 0; i < zh; i++) {
            if (nums[i] == target) {
                result = i;
                break;
            }
        }
        //没找到就继续循环找
        if (result == 0) {
            int[] data = Arrays.copyOfRange(nums, zh, nums.length);
            findSearch(data, target);
        }

        return result;

    }
}
